package com.rotsel.mh3udb.app.lists;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.rotsel.mh3udb.app.ListModels.IdNameModel;
import com.rotsel.mh3udb.app.models.*;

public final class WeaponList {
	private static Map<Integer, WeaponModel> weaponMap;//Map<weaponId, weaponModel>
    private final static int defaultCapacity = 10;

    static {
        weaponMap = new HashMap<Integer, WeaponModel>();
    }

    public static ArrayList<WeaponModel> getAllWeapons(){
        return new ArrayList<WeaponModel>(weaponMap.values());
    }

	public static ArrayList<WeaponModel> getWeaponsByIds(ArrayList<Integer> keys){
		int size = keys.size();
		ArrayList<WeaponModel> resultList = new ArrayList<WeaponModel>(size);
		WeaponModel model;
		int key;
		for(int i = 0; i < size; i++){
			key = keys.get(i);
			model = weaponMap.get(key);
			if(model != null){
				resultList.add(model);
			}
		}
		return resultList;
	}
	
	public static ArrayList<IdNameModel> getIdNameWeaponsByTypeId(int id){
        ArrayList<Integer> weaponIds = getWeaponIdsByTypeId(id);
        ArrayList<IdNameModel> modelCol = new ArrayList<IdNameModel>(weaponIds.size());

        for (int i = 0; i < weaponIds.size(); i++){
            WeaponModel weaponModel = weaponMap.get(weaponIds.get(i));
            modelCol.add(new IdNameModel(weaponModel.getId(), weaponModel.getName()));
        }

        return modelCol;
	}

    public static ArrayList<WeaponModel> getWeaponsByTypeId(int id){
        ArrayList<Integer> weaponIds = getWeaponIdsByTypeId(id);
        ArrayList<WeaponModel> modelCol = new ArrayList<WeaponModel>(weaponIds.size());

        for (int i = 0; i < weaponIds.size(); i++){
            modelCol.add(weaponMap.get(weaponIds.get(i)));
        }

        return modelCol;
    }

    private static ArrayList<Integer> getWeaponIdsByTypeId(int id){
        ArrayList<Integer> result = new ArrayList<Integer>(defaultCapacity);

        for(WeaponModel weaponModel : weaponMap.values()){
            if(weaponModel != null && weaponModel.getWeaponTypeId() == id){
                result.add(weaponModel.getId());
            }
        }

        return result;
    }

    public static WeaponModel getWeaponById(int id){
        return weaponMap.get(id);
    }

}
